<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		 <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<script type="text/javascript" src="layui1/layui.js" ></script>
		<script src="js/jQuery-2.2.2-min.js"></script>
		<link rel="stylesheet" href="layui1/css/layui.css" />
	</head>
	<body>
		
		<ul class="layui-nav" style="background-color: #202020">
    <li class="layui-nav-item" style="width: 5%"></li>
    <li class="layui-nav-item" style="width: 13%" value="logo"><a href=""><img src="imgs/yoyoga.png" style="height: 50px"></a></li>
    <li class="layui-nav-item" style="width: 12%"></li>
    <li class="layui-nav-item" style="text-align: center;width: 8%"><a href="">主页</a></li>
    <li class="layui-nav-item" style="text-align: center;width: 8%">
        <a href="#">介绍</a>
        <dl class="layui-nav-child">
            <dd><a href="">瑜伽好处</a></dd>
            <dd><a href="">瑜伽流派</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item" style="text-align: center;width: 8%"><a href="">场馆</a></li>
    <li class="layui-nav-item" style="text-align: center;width: 8%">
        <a href="#">教练</a>
        <dl class="layui-nav-child">
            <dd><a href="">移动模块</a></dd>
            <dd><a href="">后台模版</a></dd>
            <dd class="layui-this"><a href="">选中项</a></dd>
            <dd><a href="">电商平台</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item" style="text-align: center;width: 8%"><a href="">社区</a></li>



    <!--<li class="layui-nav-item" style="float: right">
        <a href="#"><img src="//t.cn/RCzsdCq" class="layui-nav-img">我</a>
        <dl class="layui-nav-child">
            <dd><a href="#">个人主页</a></dd>
            <dd><a href="#">修改信息</a></dd>
            <dd><a href="#">我的钱包</a></dd>
            <dd><a href="#">我的好友</a></dd>
            <dd><a href="#">退出</a></dd>
        </dl>
    </li>
    <li class="layui-nav-item"  style="float: right">
        <a href="">我的订单</a>
    </li>
    <li class="layui-nav-item" style="float: right">
        <a href="">消息<span class="layui-badge-dot"></span></a>
    </li>-->

    <li class="layui-nav-item"  style="float: right">
        <a href="">注册</a>
    </li>
    <li class="layui-nav-item"  style="float: right"><span style="color: #cccccc">|</span></li>
    <li class="layui-nav-item" style="float: right">
        <a href="">登陆</a>
    </li>
</ul>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
        layui.use('element', function(){
            var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

            //监听导航点击
            element.on('nav(demo)', function(elem){
                //console.log(elem)
                layer.msg(elem.text());
            });
        });
</script>

		
		
		
		
		
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px; text-align: center;">
  <legend>社区动态</legend>
</fieldset>
 <div style=" float: left; margin-left: 550px;" class="layui-btn-group">
 	 <button onclick="allpeplecansee()" type="button" class="layui-btn  layui-btn-primary ">所有人可见</button>
    <button onclick="fridendscansee()" type="button" class="layui-btn  layui-btn-primary ">好友可见</button>
    <button onclick="myselfcansee()" type="button" class="layui-btn  layui-btn-primary ">自己可见</button>
     <button id=" writeattention" type="button" class="layui-btn  layui-btn-primary " onclick="sendmoments()">发表新动态</button>
 	
 </div>
 <div id="total_div" style="width: 500px; height: 20px; float:left; margin-left: 500px;margin-top: 20px; background-color: #EEEEEE;" ></div>
<ul class="flow-default" id="moments" style="text-align: center;" >

</ul>

</body>
		<script>

		var userId;
		var userType;
/*			
	滚动加载	*/
$(document).ready(function () {
   allpeplecansee();
    $.ajax({
        url:"user1/getUserInfo",
        type:"get",
        success:function(data){
            userId = data.userId;
            userType = data.userType;
        }
    });

});

/*仅好友可见*/

           function fridendscansee() {
               $("#moments").html("");
                layui.use('flow', function () {
                    var flow = layui.flow;

                    flow.load({
                        elem: '#moments' //流加载容器
                        , loading: true
                        , isAuto: true
                        , done: function (page, next) { //执行下一页的回调
                            //模拟数据插入
                            //setTimeout(function(){

                            var lis = [];
                            $.ajax({
                                url: "moments/findMomentsToPartUser?page=" + page,

                                dataType: "json",
                                data:{
                                    "userId":userId,
                                    "userType":userType

                                },
                                success: function (res) {

                                    console.info(res);
                                    layui.each(res.momentsDTOS, function (index, item) {
                                        var name;
                                        if(item.tstudents==null&&item.ttrainers==null){
return;
                                        }
                                       else if(item.tstudents!=null&&item.ttrainers==null){
                                        name=item.tstudents[0].sName;
                                        }else  if (item.ttrainers!=null&&item.tstudents==null){
                                            name=item.ttrainers[0].tName;
                                        }else if(item.ttrainers!=null&&item.tstudents!=null){
                                          /* 学员*/
                                           if (item.musertype==0){
                                               name=item.tstudents[0].sName;
                                           }
                                           if(item.musertype==1){
                                               name=item.ttrainers[0].tName;
                                           }
                                        }
                                        var content = "";
                                        content +=
                                            "<li><div  style='width: 500px; height: auto; float:left; margin-left: 500px;margin-top: 20px; ' ><div id='name_date_headimage' style='width: 498px; height: auto; '>" +
                                            "<div id='headimage' style='width: 60px; height: 60px;float: left;'><img style='width: 58px; height: 58px;' src='headimgs/11388287d0e56ad7-53b51a5be5b5a2db-0d4a965d46d4436ed1c7053eccb6fe70.jpg'/></div><div id='name_date' style='width: 190px; height: auto; float: left;' >" +
                                            "<div style='width: 190px; height: 29px; float: left;text-align: left;'>&nbsp;&nbsp;" + name + "</div>" +
                                            "<div style='width: 190px; height: 29px; float: left;text-align: left;'>&nbsp;&nbsp;" + item.mtime + "</div>" +
                                            "</div>" +
                                            "</div>" +
                                            "<div id='text_content' style='width: 498px; height: auto;  float: left;'>" +
                                            item.mtext +
                                            "</div>" +
                                            "<div id='interval' style='width: 498px; height: auto;  float: left;'>" +
                                            "<br/>" +
                                            "</div>" +
                                            "<div id='moment_image' style='width: 498px; height: auto;  float: left;'>" +
                                            "<img src='/imagge/"+item.mimage+"' style='width: 400px;height: 300px;' align='center' />" +
                                            "</div>" +
                                            "<div id='like_delete' style='width: 498px; height: auto; float: left;'>" +
                                            "<!--点赞删除按钮-->" +
                                            "<button  type='button' class='layui-btn layui-btn-primary 'style='border: 0px; width: 60px;float: right; margin-right: 47px; margin-top: 10px; ' ><i style='font-size: 27px;' class='layui-icon layui-icon-reply-fill' onclick='reviewall(" + item.mid + ")' ></i></button>" +
                                            "<button  type='button' class='layui-btn layui-btn-primary 'style='border: 0px; width: 60px;float: right; margin-right: 20px; margin-top: 10px;' ><li><i onclick='addordellikenumber(" + item.mid + ")' id='comments_like_onenumber" + item.mid + "' style='font-size: 27px;' class='layui-icon layui-icon-praise'  ></i><span id='comments_like_number" + item.mid + "' style='float: left;margin-top: -50px;margin-left: 27px;' class='layui-badge color'>" + item.mlikenum + "</span></li></button>" +
                                            "</div>" +
                                            "<div id='total_comment' style='width: 498px; height: auto; float: left;'>" +
                                            "<div id='fiveindiv' style='width: 498px; height: auto; float: left;'>" +
                                            "<div id='comments_all_reviews'>";
                                        for (var i = 0; i < item.reviewDTOS.length; i++) {
                                            var item1 = item.reviewDTOS[i];
                                            var name;
                                            if (item1.ttrainer != null) {
                                                name = item1.ttrainer.tName;
                                            } else if (item1.tstudent != null) {
                                                name = item1.tstudent.sName;
                                            } else {
                                                continue;
                                            }
                                            content +=
                                                "<div  style='width:498px; height: auto; float: left;text-align: right;'>" +
                                                "<div id='comments_name'  style='width: 100px; height: auto; float: left;text-align: right;'>" + name + ":&nbsp;&nbsp;" + "</div>" +
                                                "<div id='comments_text'  style='width: 394px; height: auto;  float: left;text-align: left;'>" + item1.rtext + "</div>" +
                                                "</div>";
                                        }
                                        content +=
                                            "</div>" +
                                            "<div  style='width: 500px; height: auto; float:left; margin-left: 500px;margin-top: 20px;' ></div>" +
                                            "<!--评论框-->" +
                                            "<div  style='width: 498px; height: auto; float: left;' >" +
                                            "<div class='layui-input-block' style='float: left;width: 370px;margin-left: 35px;'>" +
                                            "<input id='reviewcontent" + item.mid + "' type='text' name='title' lay-verify='title' autocomplete='off' placeholder='评论' class='layui-input' style='background-color: #EEEEEE;'>" +
                                            "</div >" +
                                            "<button id='writeonereview' type='button' class='layui-btn layui-btn-primary' style='width: 60px;float: left;' onclick='review1(" + item.mid + ")'>确认</button>" +
                                            "</div>" +
                                            "<div  style='width: 500px; height: 20px; float:left;margin-top: 20px; background-color: #EEEEEE;' ></div>" +
                                            "</div>" +
                                            "</div>" +
                                            "</div>" +
                                            "</li>";


                                        lis.push(content);

                                    });

                                    next(lis.join(''), page < res.total);
                                }
                            });

                        }
                    });
                });
            }



function allpeplecansee() {
    $("#moments").html("");
    layui.use('flow', function () {
        var flow = layui.flow;

        flow.load({
            elem: '#moments' //流加载容器
            , loading: true
            , isAuto: true

            , done: function (page, next) { //执行下一页的回调

                //模拟数据插入
                //setTimeout(function(){

                var lis = [];

                $.ajax({
                    url: "moments/findMomentsToAllUser?page=" + page,

                    dataType: "json",

                    success: function (res) {
                        console.info(res.momentsDTOS);
                        layui.each(res.momentsDTOS, function (index, item) {
                            var name;
                            if(item.tstudents==null&&item.ttrainers==null){
return;
                            }
                            else if(item.tstudents!=null &&item.ttrainers==null){
                                name=item.tstudents[0].sName;
                            }else  if (item.ttrainers!=null&&item.tstudents!=null){
                                name=item.ttrainers[0].tName;
                            }
                            var content = "";
                            content +=
                                "<li><div  style='width: 500px; height: auto; float:left; margin-left: 500px;margin-top: 20px; ' ><div id='name_date_headimage' style='width: 498px; height: auto; '>" +
                                "<div id='headimage' style='width: 60px; height: 60px;float: left;'><img style='width: 58px; height: 58px;' src='headimgs/11388287d0e56ad7-53b51a5be5b5a2db-0d4a965d46d4436ed1c7053eccb6fe70.jpg'/></div><div id='name_date' style='width: 190px; height: auto; float: left;' >" +
                                "<div style='width: 190px; height: 29px; float: left;text-align: left;'>&nbsp;&nbsp;" + item.tstudents[0].sName + "</div>" +
                                "<div style='width: 190px; height: 29px; float: left;text-align: left;'>&nbsp;&nbsp;" + item.mtime + "</div>" +
                                "</div>" +
                                "</div>" +
                                "<div id='text_content' style='width: 498px; height: auto;  float: left;'>" +
                                item.mtext +
                                "</div>" +
                                "<div id='interval' style='width: 498px; height: auto;  float: left;'>" +
                                "<br/>" +
                                "</div>" +
                                "<div id='moment_image' style='width: 498px; height: auto;  float: left;'>" +
                                "<img src='/imagge/"+item.mimage+"' style='width: 400px;height: 300px;' align='center' />" +
                                "</div>" +
                                "<div id='like_delete' style='width: 498px; height: auto; float: left;'>" +
                                "<!--点赞删除按钮-->" +
                                "<button  type='button' class='layui-btn layui-btn-primary 'style='border: 0px; width: 60px;float: right; margin-right: 47px; margin-top: 10px; ' ><i style='font-size: 27px;' class='layui-icon layui-icon-reply-fill' onclick='reviewall(" + item.mid + ")' ></i></button>" +
                                "<button  type='button' class='layui-btn layui-btn-primary 'style='border: 0px; width: 60px;float: right; margin-right: 20px; margin-top: 10px;' ><li><i onclick='addordellikenumber(" + item.mid + ")' id='comments_like_onenumber" + item.mid + "' style='font-size: 27px;' class='layui-icon layui-icon-praise'  ></i><span id='comments_like_number" + item.mid + "' style='float: left;margin-top: -50px;margin-left: 27px;' class='layui-badge color'>" + item.mlikenum + "</span></li></button>" +
                                "</div>" +
                                "<div id='total_comment' style='width: 498px; height: auto; float: left;'>" +
                                "<div id='fiveindiv' style='width: 498px; height: auto; float: left;'>" +
                                "<div id='comments_all_reviews'>";
                            for (var i = 0; i < item.reviewDTOS.length; i++) {
                                var item1 = item.reviewDTOS[i];
                                var name;
                                if (item1.ttrainer != null) {
                                    name = item1.ttrainer.tName;
                                } else if (item1.tstudent != null) {
                                    name = item1.tstudent.sName;
                                } else {
                                    continue;
                                }
                                content +=
                                    "<div  style='width:498px; height: auto; float: left;text-align: right;'>" +
                                    "<div id='comments_name'  style='width: 100px; height: auto; float: left;text-align: right;'>" + name + ":&nbsp;&nbsp;" + "</div>" +
                                    "<div id='comments_text'  style='width: 394px; height: auto;  float: left;text-align: left;'>" + item1.rtext + "</div>" +
                                    "</div>";
                            }
                            content +=
                                "</div>" +
                                "<div  style='width: 500px; height: auto; float:left; margin-left: 500px;margin-top: 20px;' ></div>" +
                                "<!--评论框-->" +
                                "<div  style='width: 498px; height: auto; float: left;' >" +
                                "<div class='layui-input-block' style='float: left;width: 370px;margin-left: 35px;'>" +
                                "<input id='reviewcontent" + item.mid + "' type='text' name='title' lay-verify='title' autocomplete='off' placeholder='评论' class='layui-input' style='background-color: #EEEEEE;'>" +
                                "</div >" +
                                "<button id='writeonereview' type='button' class='layui-btn layui-btn-primary' style='width: 60px;float: left;' onclick='review(" + item.mid + ")'>确认</button>" +
                                "</div>" +
                                "<div  style='width: 500px; height: 20px; float:left;margin-top: 20px; background-color: #EEEEEE;' ></div>" +
                                "</div>" +
                                "</div>" +
                                "</div>" +
                                "</li>";
                            lis.push(content);

                        });

                        next(lis.join(''), page < res.total);
                    }
                });
            }
        });
    });
}

//仅自己可见的动态
            function myselfcansee() {
                $("#moments").html("");
                layui.use('flow', function () {
                    var flow = layui.flow;

                    flow.load({
                        elem: '#moments' //流加载容器
                        , loading: true
                        , isAuto: true
                        , done: function (page, next) { //执行下一页的回调

                            //模拟数据插入
                            //setTimeout(function(){

                            var lis = [];
                            $.ajax({
                                url: "moments/findMomentsToOnlyYou?page=" + page,


                                data:{
                                    "userId":userId,
                                    "userType":userType
                                },
                                success: function (res) {
                                    layui.each(res.momentsList, function (index, item) {
                                        //alert(item.mImage);
                                        var content = "";
                                        content +=
                                            "<li><div  style='width: 500px; height: auto; float:left; margin-left: 500px;margin-top: 20px; ' ><div id='name_date_headimage' style='width: 498px; height: auto; '>" +
                                            "<div id='headimage' style='width: 60px; height: 60px;float: left;'><img style='width: 58px; height: 58px;' src='headimgs/11388287d0e56ad7-53b51a5be5b5a2db-0d4a965d46d4436ed1c7053eccb6fe70.jpg'/></div><div id='name_date' style='width: 190px; height: auto; float: left;' >" ;


                                        for (var i = 0; i < res.momentsList.length; i++) {
                                            var name;
                                            if(res.student!=null){
                                                name=res.student.sName;
                                            }else if(res.tTrainer!=null){
                                                name=res.tTrainer.tName;
                                            }else{
                                                continue
                                            }
                                        }
                                            content +=
                                                "<div style='width: 190px; height: 29px; float: left;text-align: left;'>&nbsp;&nbsp;"+name+"</div>" ;

                                            content +=

                                            "<div style='width: 190px; height: 29px; float: left;text-align: left;'>&nbsp;&nbsp;" + item.mTime + "</div>" +
                                            "</div>" +
                                            "</div>" +
                                            "<div id='text_content' style='width: 498px; height: auto;  float: left;'>" +
                                                item.mText +
                                            "</div>" +
                                            "<div id='interval' style='width: 498px; height: auto;  float: left;'>" +
                                            "<br/>" +
                                            "</div>" +
                                            "<div id='moment_image' style='width: 498px; height: auto;  float: left;'>" +
                                            "<img src='/imagge/"+item.mImage+"' style='width: 400px;height: 300px;' align='center' />" +
                                            "</div>" +
                                                "<button onclick='delthismoments("+item.mId+")' type='button' class='layui-btn layui-btn-primary 'style='border: 0px; width: 60px;float: right; margin-right: 47px; margin-top: 10px; ' ><i style='font-size: 27px;' class='layui-icon layui-icon-delete' ></i></button>" +
                                           " <div  style='width: 500px; height: 20px; float:left;margin-top: 20px; background-color: #EEEEEE;' ></div>"+
                                            "</div>" +
                                            "</li>";
                                        lis.push(content);

                                    });

                                    next(lis.join(''), page < res.total);
                                }
                            });
                    }
                    });
                });
            }

//删除仅自己可见的动态
            function delthismoments(mId) {
                //alert(mId);
                $.ajax({
                    url:"moments/delMomentsById",
                    data:{
                        "mId":mId
                    },
                    success:function (res) {
                        if (res.indexOf("成功")!=-1){
                            myselfcansee();
                            layui.use('layer', function(){
                                var layer = layui.layer;
                                layer.ready(function(){
                                    layer.msg("已删除!");
                                });

                            });

                        } else{
                            layui.use('layer', function(){
                                var layer = layui.layer;
                                layer.ready(function(){
                                    layer.msg("删除失败!");
                                });

                            });
                        }

                    }
                });
            }
		</script>
    <script>
        function reviewall(mid) {
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.ready(function(){
                    layer.msg("我就是个图标，评论在下面!");
                });

            });
        }

//点赞
           function addordellikenumber(mid){
               if($("#comments_like_number"+mid).hasClass("color")){
                   $.ajax({
                       url:"moments/addOneLikeNum",
                       data:{
                           "currentLikenum":$("#comments_like_number"+mid).text(),
                           "mid":mid,

                           "likenum":1
                       },
                       success:function (res) {
                           console.info(res)
                           if(res.indexOf("成功")!=-1){

                               $("#comments_like_number"+mid).removeClass("color");
                               $("#comments_like_onenumber"+mid).attr("style","font-size: 27px;color: red");
                               $("#comments_like_number"+mid).text(parseInt($("#comments_like_number"+mid).text())+1);
                           }
                       }
                   });
               }else{
                    $.ajax({
                        url:"moments/addOneLikeNum",
                        data:{
                            "currentLikenum":$("#comments_like_number"+mid).text(),
                            "mid":mid,

                            "likenum":-1
                        },
                        success:function (res) {
                            if (res.indexOf("成功") != -1) {
                                $("#comments_like_number"+mid).addClass("color");
                                $("#comments_like_onenumber"+mid).attr("style","font-size: 27px;");
                                $("#comments_like_number"+mid).text(parseInt($("#comments_like_number"+mid).text())-1);
                            }
                        }
                    });


               }
           }
            $(document).ready(function(){

        });

          //所有人可见添加一个评论
        function review(mid) {
            if($("#reviewcontent"+mid).val()!=null&&$("#reviewcontent"+mid).val()!=""&&$("#reviewcontent"+mid).val()!=undefined){
                //alert(11111111111111);
               $.ajax({
                  url:"review/addReview",
                   type:"get",
                   data:{
                       "rMId":mid,
                       "rText":$("#reviewcontent"+mid).val()
                   },
                   success:function (res) {
                     if (res.indexOf("成功")!=-1){
                         allpeplecansee();

                     }else {
                         layui.use('layer', function(){
                             var layer = layui.layer;
                             layer.ready(function(){
                                 layer.msg("评论失败!");
                             });

                         });
                     }
                   }
               });
            }else {
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.ready(function(){
                        layer.msg("评论不能为空!");
                    });

                });

            }
        }


        //仅好友可见添加一条评论

           function review1(mid) {
               if($("#reviewcontent"+mid).val()!=null&&$("#reviewcontent"+mid).val()!=""&&$("#reviewcontent"+mid).val()!=undefined){
                   $.ajax({
                       url:"review/addReview",
                       type:"get",
                       data:{
                           "rMId":mid,
                           "rText":$("#reviewcontent"+mid).val()
                       },
                       success:function (res) {
                           if (res.indexOf("成功")!=-1){
                               //window.location.reload();
                               fridendscansee();

                           }else {
                               layui.use('layer', function(){
                                   var layer = layui.layer;
                                   layer.ready(function(){
                                       layer.msg("评论失败!");
                                   });

                               });
                           }
                       }
                   });
               }else {
                   layui.use('layer', function(){
                       var layer = layui.layer;
                       layer.ready(function(){
                           layer.msg("评论不能为空!");
                       });

                   });

               }
           }
    </script>
<!--发表动态-->
    <script>

            function sendmoments(){
                layui.use('layer', function(){
                 layer = layui.layer;
                //页面层
                    layer.ready(function(){
                layer.open({
                    type:2,
                    title:"说说",
                   // skin: 'layui-layer-rim', //加上边框
                    area: ['700px', '400px'],
                    offset:"60px",
                    maxmin:true,//宽高
                    scrollbar: false ,
                    content:"/sendmoments.html",
                    btn:['确认','取消']
                    ,yes:function(index,layero){

                        //layer.msg("222222");
                        var res= window["layui-layer-iframe" + index].callbackdata();
                       // console.log(res);
                        //获取弹出层返回的图片path等
                        layer.close(index);
                        var mPermission=res.permissionnum;
                        var mImage =res.imagepath;
                        var mText=res.sendmoments_content;
                        $.ajax({
                             url:"moments/addOneMoments",
                            data:{
                                 "mPermission":mPermission,
                                "mImage":mImage,
                                "mText":mText,
                                "userId":userId,
                                "userType":userType
                            },
                            success:function (res) {
                                 if(res.indexOf("成功")!=-1){

                                     layui.use('layer', function(){
                                         var layer = layui.layer;
                                         layer.ready(function(){
                                             layer.msg("发表成功!");
                                         });

                                     });
                                     if(mPermission==0){
                                         myselfcansee();
                                     }
                                     if(mPermission==1){
                                         fridendscansee();
                                     }
                                     if(mPermission==2){
                                         allpeplecansee();
                                     }

                                 }   else{
                                     layui.use('layer', function(){
                                         var layer = layui.layer;
                                         layer.ready(function(){
                                             layer.msg("发表失败!");
                                         });

                                     });
                                 }
                            }
                        });
                    }
                });

                    });

                });
        }

    </script>

</html>
